package insight.Builder;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

/**
 * @author huu
 * @create 2025-08-26-14:50
 * @description: http中的builder模式
 */
public class httpDemo {
    public static void main(String[] args) throws IOException, InterruptedException {
        //说明两个概念，第一不可变参数，这里可以给httpClient设置超时时间，但之后我们不能修改这个时间参数了
        HttpClient httpClient = HttpClient.newBuilder()
                .version(HttpClient.Version.HTTP_2)
                .build();
        //一次性对象就是这个请求
        HttpRequest httpRequest = HttpRequest.newBuilder()
                .uri(URI.create("https://www.baidu.com"))
                .build();
        httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
    }
}
